package com.xingqing.repository;

import com.xingqing.domain.entity.WorkExperience;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WorkExperienceMapper {
    
    @Select("SELECT * FROM work_experience ORDER BY start_date DESC")
    List<WorkExperience> selectAll();
    
    @Select("SELECT * FROM work_experience WHERE id = #{id}")
    WorkExperience selectById(Long id);
    
    @Select("SELECT * FROM work_experience WHERE emp_id = #{empId} ORDER BY start_date DESC")
    List<WorkExperience> selectByEmpId(Long empId);
    
    @Insert("INSERT INTO work_experience (start_date, end_date, company_name, position, emp_id, create_time, update_time) " +
            "VALUES (#{startDate}, #{endDate}, #{companyName}, #{position}, #{empId}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(WorkExperience workExperience);
    
    @Insert("<script>" +
            "INSERT INTO work_experience (start_date, end_date, company_name, position, emp_id, create_time, update_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.startDate}, #{item.endDate}, #{item.companyName}, #{item.position}, #{item.empId}, #{item.createTime}, #{item.updateTime})" +
            "</foreach>" +
            "</script>")
    void insertBatch(@Param("list") List<WorkExperience> workExperiences);
    
    @Update("UPDATE work_experience SET start_date = #{startDate}, end_date = #{endDate}, " +
            "company_name = #{companyName}, position = #{position}, emp_id = #{empId}, " +
            "update_time = #{updateTime} WHERE id = #{id}")
    void updateById(WorkExperience workExperience);
    
    @Delete("DELETE FROM work_experience WHERE id = #{id}")
    void deleteById(Long id);
    
    @Delete("DELETE FROM work_experience WHERE emp_id = #{empId}")
    void deleteByEmpId(Long empId);
}